<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客户管理</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>
<script type="text/javascript">
function deltipOpen(purchaseId) {
    $("#purchaseId").val(purchaseId);
	$("#deltip").fadeIn(200);
}
function deltipClose(num) {
    if(num==1){
      var purchaseId = $("#purchaseId").val();
      location.href="/erp/purchase/deleteByPurchaseId?purchaseId="+purchaseId;
    }
	$("#deltip").fadeOut(200);
}
function examinetipOpen(purchaseId) {
    $("#purchaseId").val(purchaseId);
	$("#examinetip").fadeIn(200);
}
function examinetipclose(num) {
    if(num==1){
     var purchaseId = $("#purchaseId").val();
     var checkUid = $("#checkUname").val();
     // console.log("审核单号"+purchaseId+"，审核人"+checkUid);
     location.href="/erp/purchase/subExamine?purchaseId="+purchaseId+"&checkUid="+checkUid;
    }
	$("#examinetip").fadeOut(200);
}
</script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>采购单管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form th:action="@{/purchase/lists}" method="post" name="conditionForm">
    <ul class="tools">
      <li> 采购单编号:
        <input type="text" name="purchaseId" th:value="${pParam.purchaseId}"/>
      </li>
      <li> 采购时间:
        <input type="date" name="startDate" th:value="${#dates.format(pParam.startDate,'yyyy-MM-dd')}"/>-
          <input type="date" name="endDate" th:value="${#dates.format(pParam.endDate,'yyyy-MM-dd')}"/>
      </li>
      <li> 金额:
        <input type="text" class="stinput" name="startMoney" th:value="${pParam.startMoney}"/>-<input type="text" class="stinput" name="endMoney" th:value="${pParam.endMoney}"/>
      </li>
      <li> 审核状态：
        <select name="checkStatus">
          <option value="">请选择</option>
          <option value="1" th:selected="${pParam.checkStatus==1}">未审核</option>
          <option value="2" th:selected="${pParam.checkStatus==2}">审核中</option>
          <option value="3" th:selected="${pParam.checkStatus==3}">审核通过</option>
          <option value="4" th:selected="${pParam.checkStatus==4}">审核未通过</option>
        </select>
      </li>
      <li class="subBut" onclick="query()"><img th:src="@{/images/t06.png}" />查询</li>
      <li th:if="${session.users.jobId!=4}" class="subBut" onclick="window.location.href='/erp/purchase/toSave'"><img th:src="@{/images/t01.png}" />添加</li>
      <li class="subBut" onclick="empty()"><img th:src="@{/images/t03.png}"/>清空</li>
    </ul>
    <table class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>采购单编号</th>
          <th>采购时间</th>
          <th>金额</th>
          <th>操作人</th>
          <th>审核状态</th>
          <th>审核人</th>
          <th>审核时间</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr th:each="cg,var:${CgPin.list}" th:switch="${cg.checkStatus}">
          <td th:text="${(CgPin.pageNum-1)*CgPin.pageSize+var.count}">1</td>
          <td th:text="${cg.purchaseId}">CG201701270001</td>
          <td th:text="${#dates.format(cg.purchaseTime,'yyyy-MM-dd')}">2017-01-25 15:05:05</td>
          <td th:text="'￥'+${cg.totalMoney}">￥9,876,582</td>
          <td th:text="${cg.creatUser.uname}">关羽</td>
          <td th:case="1">未审核</td>
          <td th:case="2">审核中</td>
          <td th:case="3">审核通过</td>
          <td th:case="4">审核未通过</td>
          <td th:text="${cg.checkUser!=null?cg.checkUser.uname:''}"></td>
          <td th:text="${#dates.format(cg.checkTime,'yyyy-MM-dd')}"></td>
          <!--未审核-->
          <td th:if="${session.users.jobId!=4 and cg.checkStatus==1}">
            <a th:href="@{/purchase/toUpdate?purchaseId=}+${cg.purchaseId}+'&productId='+${cg.cDetails.productId}" class="tablelink">修改</a>
            <a href="javascript:void(0);" class="tablelink" th:onclick="deltipOpen([[${cg.purchaseId}]])">删除</a>
            <a href="javascript:void(0);" class="tablelink tocheck" th:onclick="examinetipOpen([[${cg.purchaseId}]])">提交审核</a>
          </td>
          <!--审核中-->
          <td th:if="${session.users.jobId!=4 and cg.checkStatus==2}">
            <a th:href="@{/purchase/details?purchaseId=}+${cg.purchaseId}" class="tablelink">查看详情</a>
          </td>
          <!--审核通过-->
          <td th:if="${session.users.jobId!=4 and cg.checkStatus==3}">
            <a th:href="@{/purchase/details?purchaseId=}+${cg.purchaseId}" class="tablelink">查看详情</a>
            <a th:href="@{/purchase/RkDetails?purchaseId=}+${cg.purchaseId}" th:if="${cg.cgState==1}" class="tablelink">入库详情</a>
          </td>
          <!--审核未通过-->
          <td th:if="${session.users.jobId!=4 and cg.checkStatus==4}">
              <a th:href="@{/purchase/toUpdate?purchaseId=}+${cg.purchaseId}+'&productId='+${cg.cDetails.productId}" class="tablelink">修改</a>
              <a href="javascript:void(0);" class="tablelink tocheck" th:onclick="examinetipOpen([[${cg.purchaseId}]])">提交审核</a>
          </td>

          <!--经理只能查看-->
          <td th:if="${session.users.jobId==4}">
            <a th:href="@{/purchase/details?purchaseId=}+${cg.purchaseId}" class="tablelink">查看详情</a>
          </td>
        </tr>
      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue" th:text="${CgPin.total}">1256</i>条记录，当前显示第&nbsp;<i class="blue" th:text="${CgPin.pageNum}">2&nbsp;</i>页</div>
        <ul class="paginList">
            <li class="paginItem" th:onclick="goPage([[${CgPin.pageNum-1}]])"><a href="javascript:;"><span class="pagepre"></span></a></li>
            <li class="paginItem" th:onclick="goPage(1)" th:class="${CgPin.pageNum==1?'paginItem current':'paginItem'}"><a href="javascript:;">1</a></li>

            <li th:each="p:${listPage}" th:class="${CgPin.pageNum==p?'paginItem current':'paginItem'}" th:onclick="goPage([[${p}]])"><a th:text="${p}" href="javascript:;">2</a></li>

            <li class="paginItem" th:if="${CgPin.pages!=1 and CgPin.pages!=0}" th:onclick="goPage([[${CgPin.pages}]])" th:class="${CgPin.pageNum==CgPin.pages?'paginItem current':'paginItem'}"><a href="javascript:;" th:text="${CgPin.pages}" id="pages" >10</a></li>
            <li class="paginItem"  th:onclick="goPage([[${CgPin.pageNum+1}]])"><a href="javascript:;"><span class="pagenxt"></span></a></li>
        </ul>
    </div>
  </form>
  <!-- 删除提示框 -->
  <div id="deltip" class="tip">
    <div class="tiptop"><span>提示信息</span><a onclick="deltipClose()"></a></div>
    <div class="tipinfo"> <span><img th:src="@{/images/ticon.png}" /></span>
      <div class="tipright">
        <p>是否确认删除此条信息？</p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" onclick="deltipClose(1)" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="deltipClose()" />
    </div>
  </div>

  <!-- 审批提示框 -->
  <div id="examinetip" class="tip">
    <div class="tiptop">
    	<span>提示信息</span><a onclick="examinetipclose()"></a>
    </div>
    <div class="tipinfo1">

        部门：
            <select class="dfselect">
                <option>采购部</option>
            </select>
			<p/>
            职位：
            <select class="dfselect">
                <option>部门经理</option>
            </select>
   			<p/>
            姓名：
            <select class="dfselect" id="checkUname">

            </select>
			<p/>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" onclick="examinetipclose(1)" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="examinetipclose()" />
    </div>
  </div>
  <input type="hidden" name="purchaseId" id="purchaseId">
</div>
<script type="text/javascript">
  // 获取采购部经理
  $(".tocheck").click(function () {
    $.get("/erp/purchase/getUsers",function (data) {
      var str = "<option>请选择</option>";
      $.each(data,function (i, e) {
          str += "<option value="+e.uid+">"+e.uname+"</option>";
      })
      $("#checkUname").html("");
      $("#checkUname").append(str);

    },"json");
  });
  /*


                <option>曹操</option>
   */

  function empty() {
    $("input[name=purchaseId]").val("");
    $("input[name=startDate]").val("");
    $("input[name=endDate]").val("");
    $("input[name=startMoney]").val("");
    $("input[name=endMoney]").val("");
    $("select[name=checkStatus]").val("");
  }

    // 表单提交
    function query(){
       $("form[name=conditionForm]").submit();
    }

    // 页面跳转
    function goPage(num){
        var purchaseId = $("input[name=purchaseId]").val();
        var startDate = $("input[name=startDate]").val();
        var endDate = $("input[name=endDate]").val();
        var startMoney = $("input[name=startMoney]").val();
        var endMoney = $("input[name=endMoney]").val();
        var checkStatus = $("select[name=checkStatus]").val();

        // 最后一页
        var pages = $("#pages").text();
        if(num>=1 && num<=pages){
            location.href="/erp/purchase/lists?pageno="+num+"&purchaseId="+purchaseId+"&startDate="+startDate
            +"&endDate="+endDate+"&startMoney="+startMoney+"&endMoney="+endMoney+"&checkStatus="+checkStatus;
        }
    }


    $('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
</html>
